// 是否横屏的判断
import { ref } from 'vue'
import { onUnload } from '@dcloudio/uni-app'

export default function useIsLandscape() {
  const isLandscape = ref(false)

  // 获取当前设备的屏幕尺寸信息
  const sysInfo = uni.getSystemInfoSync()
  
  // 横屏的判断标准是：宽高比在一定比例,比例不在这范围里，显示样式会有问题
  const rate = sysInfo.windowWidth / sysInfo.windowHeight
  isLandscape.value = rate > 1.6 && rate < 2.3


  const handleWindowResize = (res) => {
		const rate = res.size.windowWidth / res.size.windowHeight
		isLandscape.value = rate > 1.6 && rate < 2.3
	
  }

  uni.onWindowResize(handleWindowResize)

  onUnload(() => {
    uni.offWindowResize(handleWindowResize)
  })

  return {
    isLandscape
  }
}